import { Application } from 'egg';
import { STRING, INTEGER, Optional, Model } from 'sequelize';

export interface UserAttributes {
  userId: number;
  username: string;
  password: string;
  gender?: '男' | '女';
  avatar?: string;
  nickname?: string;
  area?: string;
  birthday?: string;
  height?: number;
  motto?: string;
}

interface UserCreationAttributes extends Optional<UserAttributes, 'userId'> {}

export default (app: Application) => {
  const User = app.model.define<Model<UserAttributes, UserCreationAttributes>>('user', {
    userId: { type: INTEGER, primaryKey: true, autoIncrement: true, field: 'userId' },
    username: { type: STRING(50), allowNull: false },
    password: { type: STRING(50), allowNull: false },
    gender: { type: STRING(50), allowNull: true },
    avatar: { type: STRING(500), allowNull: true },
    nickname: { type: STRING(50), allowNull: true },
    area: { type: STRING(50), allowNull: true },
    birthday: { type: STRING(20), allowNull: true },
    height: { type: INTEGER, allowNull: true },
    motto: { type: STRING(50), allowNull: true },
  }, {
    timestamps: false,
  });

  return User;
};
